<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Document</title>
        <script src="../vue.js"></script>
    </head>
    <body>
        <div id="app">
            <p>姓名: {{person.name}}</p>
            <p>性别: {{person.sex}}</p>
            <p>身高: {{person.height}}</p>
            <p>体重: {{person.weight}}</p>
            <button @click="handleClick">按钮</button>
        </div>
        <script>
            let vm = new Vue({
                el: '#app',
                data() {
                    return {
                        person: {
                            name: 'wangjin',
                            height: '185cm',
                            weight: '70kg',
                        },
                    };
                },
                methods: {
                    handleClick() {
                        // 给性别赋值
                        // this.person.sex = 'boy';
                        /*
                            vm.$set( target, propertyName/index, value )
                            target: 目标对象(你要修改的那个对象),这里是person
                            propertyName: 属性名,你要修改这个对象上的哪个属性
                            value: 值
                        */
                        this.$set(this.person, 'sex', 'boy'); // getter和setter
                        console.log(this.person);
                    },
                },
            });
        </script>
    </body>
</html>
